<template>
  <div class="section-two" ref="wrap">
    <div class="border-row"></div>
    <div class="border-col"></div>
    
    <div class="section-header-two">期望岗位</div>

     <div id="charts" ref="charts" :style="chartsDom" v-show="jz"></div>
    <div class="container_jz" :style="chartsDom" v-if="!jz">
              <div class="circle_jz"></div>
              <div class="circle_jz"></div>
              <div class="circle_jz"></div>
            </div>
  </div>
</template>
<script>
import {
  get_TalentMonitor_PopularPosts
} from '@/api/data'
export default {
  data () {
    return {
      chartData: [],
      jz:true
    }
  },
  props: ['height','dateProp'],
  computed: {
    chartsDom() {
      return {
        width: (document.documentElement.clientWidth-30)/4-15 - 10+ 'px',
        height: this.height - 30 - 10 + 'px',
        'z-index': 100,
        position: 'relative'
      }
    }
  },
  mounted() {
    this.$nextTick(_=>{
      this.init();
    });
  },
  methods: {
    init() {
      this.jz=false
      get_TalentMonitor_PopularPosts(this.dateProp)
      .then(({data:{data}})=>{
        if(data && data.length) {
          let newData = data.sort((a,b) => b.Number - a.Number).slice(0,8);

          this.chartData = newData.filter(v=>{
            v['name'] = v.PostName;
            v['value'] = Number(v.Number);
            return v;
          });
          this.jz=true
          this.chartsInit();
        }else{
          this.chartData = null;
        }
        
      });
    },
    chartsInit() {
      let option = {

        legend: {
          bottom: 0,
          textStyle: {
            color: 'rgba(255, 255, 255, 0.3)'
          }
        },

        tooltip: {
            show: true,
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c}人 ({d}%)'
        },
        color: ['#4c7ef0','#b86cc6','#ff7899','#7fe5ff','#fed866','#5eca41','#00bcd4','#795548'],
        series: [
            {
                name: '期望岗位',
                type: 'pie',
                radius: '55%',
                center: ['50%', '40%'],
                data: this.chartData,
                roseType: 'radius',
                label: {
                    color: 'rgba(255, 255, 255, 0.3)',
                    formatter: (params) => {
                      return params.data.name
                    }
                },
                labelLine: {
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 0.3)'
                    },
                    smooth: 0.2,
                    length: 10,
                    length2: 20
                },
                itemStyle: {
                    shadowBlur: 200,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                },

                animationType: 'scale',
                animationEasing: 'elasticOut',
                animationDelay: function (idx) {
                    return Math.random() * 200;
                }
            }
        ]
      };
      let chart = this.$echarts.init(this.$refs.charts);
      chart.setOption(option);
    }
  },
}
</script>
<style lang="stylus" scoped>
  .section
    width 100%
    height 100%
</style>